
const util = require('../../utils/util.js');
const http = util.http;

Page({
  data: {
    shopList: [],
    params: {
      page: 1,
      pageSize: 10
    }
  },
  // 进入申请页面 别忘记将shop_id传进去
  goApplyPage: function (e) {
    const id = e.target.dataset.id;
    wx.navigateTo({
      url: `./apply/index?id=${id}`,
    })
  },
  // 进入管理页面
  goManagePage: function (e) {
    const id = e.target.dataset.id;
    wx.navigateTo({
      url: `./manage/index?id=${id}`,
    })
  },
  // 进入搜索页面
  wxSearchTab: function () {
    wx.navigateTo({
      url: './search/index'
    })
  },
  onLoad: function () {
    const params = this.data.params;
    http('/parts/myShopList', 'post', params)
    .then((data) => {
      this.setData({
        shopList: data.list
      });
    });
  },
  // 下触底加载
  onReachBottom: function () {
    const params = this.data.params;
    params.page ++;
    http('/parts/myShopList', 'post', params)
      .then((data) => {
        console.log(data.list);
        let shopList = this.data.shopList.concat(data.list);
        console.log(shopList);
        this.setData({
          shopList: shopList
        });
      });
  },
})
